package com.manage.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.manage.common.R;
import com.manage.service.FlowerManageService;
import com.manage.pojo.FlowerManage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 管理员
 */
@CrossOrigin // 解决跨域
@RestController
@RequestMapping("/flower-manage")
public class FlowerManageController {

    @Autowired
    private FlowerManageService flowerManageService;

    /**
     * 管理端注册
     * @param flowerManage
     */
    @PostMapping("/register")
    public R register(@RequestBody FlowerManage flowerManage) {
        // 调用业务层
        return flowerManageService.register(flowerManage);
    }

    /**
     * 管理员登录
     * @param flowerManage
     * @return
     */
    @PostMapping("/login")
    public R login(@RequestBody FlowerManage flowerManage) {
        System.out.println(flowerManage);
        return flowerManageService.login(flowerManage);
    }

    /**
     * 管理端修改用户信息
     * @param flowerManage
     * @return
     */
    @PostMapping("/update_user")
    public R updateUser(@RequestBody FlowerManage flowerManage) {
        boolean flag = flowerManageService.updateById(flowerManage);
        if (flag){
            return R.success("修改成功！");
        }else {
            return R.error("修改失败");
        }
    }

    /**
     * 查询用户信息
     * @param userId
     * @return
     */
    @GetMapping("/select_user")
    public R selectUser(@RequestParam("userId") String userId){
        return R.success(flowerManageService.getOne(Wrappers.<FlowerManage>lambdaQuery().eq(FlowerManage::getUserId,userId)),"还原成功！");
    }

}

